package chixing.day18.synchronized_demo2;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Vector;

public class Test {
    public static void main(String[] args) {
        //StringBuilder用于单线程经常修改的字符串
        StringBuilder sBuilder = new StringBuilder("hello");
        sBuilder.append("run");
        sBuilder.reverse();
        //StringBuffer 适用于多线程经常修改的字符串
        StringBuffer sBuffer = new StringBuffer("hello");
        sBuffer.append("stop");//StringBuffer的append()加了synchronized关键字

        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("hello");
        Vector<String> vector = new Vector<>();
        vector.add("hello");//Vector的add()加了synchronized关键字

        HashMap<Integer,Integer> map = new HashMap<>();
        map.put(1,12);
        map.put(null,null);//hashMap的key和value可以为空
        Hashtable<Integer,Integer> hashtable = new Hashtable<>();
        hashtable.put(45,2);//Hashtable的put()方法加了synchronized关键字
        hashtable.put(null,null);//NullPointerException异常，Hashtable的key，value 不能为空


    }
}
